<?php
function textilize($text) {
  include_once("Textile.php");
  $textile = new Textile;
  return $textile->process($text);
}
function parselinks($input) {
  $final = "";
  $split = split("}",$input);
  for($i=0; $i<count($split)-1; $i++) {
    $segment = $split[$i];
    $split2 = split("{",$segment);
    $final .= $split2[0];
    $linktarget = $split2[1];
    // does the linked page exist?
    $linkexists = false;
    foreach($db->pages->page as $currentpage) {
      if($currentpage['title'] == $linktarget) {
        $linkexists = true;
      }
    }
    //if($linkexists) {
      $final .= "<a href='?show=$linktarget'>$linktarget</a>";
    //} else {
      //$final .= "<a href='?edit=$linktarget' class='nonexistentlink'>$linktarget</a>";
    //}
  }
  $final .= $split[count($split)-1];
  return $final;
}
/*
function distinguishLinks($input) {
  $final = "";
  $split = split("</a>",$input);
  for($i=0; $i<count($split)-1, $i++) {
    $segment = $split[$i];
    $split2 = split("<a href=",$segment);
    $final .= $split2[0];
    if(!strstr($split2[1],"http://") == false) {
      $final .= "<a class='externallink' href=".$split2[1];
    }
  }
  $final .= $split[count($split)-1];
  return $final;
}
*/
function dbsize() {
  return round(filesize("database.xml")/1024);
}
function listCategories($item) {
  foreach(split(" ",$item['categories']) as $category) {
    echo "<a href='?category=$category'>$category</a> ";
  }
}
?>